const app = getApp()
import {storeIndex} from '../../api/api.js';
import { tips } from '../../utils/show.js'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    height: app.globalData.height * 2 + 20,
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '兑积分  ', //导航栏 中间的标题
      img: "../../image/index.png"
    },
    score:'0',
    list: [],
    imgUrl: app.globalData.imgUrl
  },

  bindViewTap: function () {
    this.commonCheckJump('/pages/fun/convertible/convertible');
  },

  bindViewTap2: function () {
    this.commonCheckJump('/pages/fun/integral/integral');
  },

  commonCheckJump(url) {
    if (app.globalData.hasLogin && app.globalData.hasMobile) {
      wx.navigateTo({ url })
    } else {
      wx.navigateTo({ url: '/pages/me/login/login' })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getStoreList();
  },

  getStoreList(){
    const data = {
      openid: app.globalData.openid,
    }
    app.showLoading();
    storeIndex(data).then(res=>{
      app.hideLoading();
      if(res.code == 0){
        const data = res.data.user;
        // console.log(data)
        let score = 0;
        if (data) {
          score = data.total_point - data.used_point
        }
        let list = res.data.goods;
        this.setData({
          list,
          score
        });
      }else{
        tips("数据出错");
      }
    })
  },
  // 跳转到商品详情 element
  goGoodsDetals (e) {
    e.currentTarget.dataset.id;
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({ url: '/pages/fun/details/details?id=' + id })
  },

  onShow () {
    const user = app.globalData.userInfo || {};
    const arr = Object.keys(user);
    let score = 0;
    if (arr.length !== 0) {
      if (user.total_point)  score = parseInt(user.total_point) - parseInt(user.used_point);
      this.setData({ score })
    }
  }
})